# Contributor: Joe Holden <jwh@zorins.us>
# Contributor: Michał Polański <michal@polanski.me>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=traefik
pkgver=2.11.2
pkgrel=0
pkgdesc="The Cloud Native Edge Router"
url="https://traefik.io/"
arch="all"
arch="$arch !x86 !armhf !armv7 !s390x !ppc64le !riscv64" # failing tests
license="MIT"
makedepends="go go-bindata"
checkdepends="tzdata"
install="$pkgname.pre-install"
pkgusers="$pkgname"
pkggroups="$pkgname"
subpackages="$pkgname-openrc"
options="net setcap chmod-clean"
source="$pkgname-$pkgver.tar.gz::https://github.com/traefik/traefik/releases/download/v$pkgver/traefik-v$pkgver.src.tar.gz
	traefik.initd
	traefik.confd
	traefik.yaml
	"
builddir="$srcdir"

# secfixes:
#   2.9.10-r0:
#     - CVE-2023-29013
#     - CVE-2023-24534
#   2.9.6-r0:
#     - CVE-2022-23469
#     - CVE-2022-46153
#   2.2.8-r0:
#     - CVE-2020-15129

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	go generate -v
	go build \
		-ldflags "-X github.com/traefik/traefik/v2/pkg/version.Version=$pkgver" \
		-v -o bin/$pkgname \
		./cmd/$pkgname
}

check() {
	# shellcheck disable=2046
	CI=1 \
	go test $(go list ./pkg/... | grep -Ev '(pkg/server)')
}

package() {
	install -Dm755 bin/$pkgname "$pkgdir"/usr/sbin/$pkgname

	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -dm775 -o $pkgname -g $pkgname "$pkgdir"/var/log/$pkgname

	install -dm750 -o $pkgname -g $pkgname "$pkgdir"/etc/$pkgname
	install -m644 -o $pkgname -g $pkgname "$srcdir"/traefik.yaml \
		"$pkgdir"/etc/$pkgname/$pkgname.yaml
}

sha512sums="
0bfe1542da3f7ae0b6c08300ba2f42f7a936d28406b96a18a585694018acaf301629c29f5fc219250aa85a652ada75222a9ca27dbf97060b2a224cefee84119c  traefik-2.11.2.tar.gz
d5a64e46ebafebd1352fda2fae5c3b6ccb58d3191583b06efbba9eaf0b444d4a7b6743a347a13ad79ca207ddeda7ab8d7387ffd7d4f9160ec80b5f2521bf8808  traefik.initd
bbc0bb6825f8847ef0ee18b7194afc4e1443041727022e435e48249744b1230b3422ff9d20a6b42d2e3615e57c10254611fe1e999b847e7b4a4d5954bd677cf2  traefik.confd
ae87af859fa64aa35a5f8493dd29630d4ed8c6c8e6e70083bb03b2eded5cd1ab46979901fca5d495d2dd918bf1bbf0a553a43da38b9507a2437874bfcf09bc1a  traefik.yaml
"
